﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Core.LockStep
{
    public static class PrecisionExtend
    {
        public const float PRECISION = 1000;

        public static int PrecisionInt(this float value)
        {
            var producNumber = value * PRECISION;
            var decimalValue = producNumber % 1;
            return (int)producNumber + Mathf.RoundToInt(decimalValue);
        }

        public static float PrecisionFloat(this int value)
        {
            return value / PRECISION;
        }

        public static Vector2Int PrecisionV2I(this Vector2 value)
        {
            return new Vector2Int(value.x.PrecisionInt(), value.y.PrecisionInt());
        }

        public static Vector2 PrecisionV2(this Vector2Int value)
        {
            return new Vector2(value.x.PrecisionFloat(), value.y.PrecisionFloat());
        }

        public static Vector3Int PrecisionV3I(this Vector3 value)
        {
            return new Vector3Int(value.x.PrecisionInt(), value.y.PrecisionInt(), value.z.PrecisionInt());
        }

        public static Vector3 PrecisionV3(this Vector3Int value)
        {
            return new Vector3(value.x.PrecisionFloat(), value.y.PrecisionFloat(), value.z.PrecisionFloat());
        }
    }
}